/*
 * Copyright (c) 2018. paascloud.net All Rights Reserved.
 * 项目名称：paascloud快速搭建企业级分布式微服务平台
 * 类名称：RedisInitRunner.java
 * 创建人：刘兆明
 * 联系方式：paascloud.net@gmail.com
 * 开源地址: https://github.com/paascloud
 * 博客地址: http://blog.paascloud.net
 * 项目官网: http://paascloud.net
 */

package com.csun.cmny.provider.config;

import com.csun.cmny.provider.model.domain.UacGroupLanguage;
import com.csun.cmny.provider.service.UacGroupLanguageService;
import com.csun.cmny.util.RedisKeyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * The class Redis init runner.
 *
 * @author paascloud.net @gmail.com
 */
@Component
@Order(value = 1)
@Slf4j
public class RedisInitRunner implements CommandLineRunner {

	@Resource
	private UacGroupLanguageService uacGroupLanguageService;
	@Resource
	private RedisTemplate<String, Object> redisTemplate;

	/**
	 * Run.
	 *
	 * @param args the args
	 */
	@Override
	public void run(String... args) {

		log.info(">>>>>>>>>>>>>>>服务启动执行，执行加载数据等操作 11111111 <<<<<<<<<<<<<");


		log.info(">>>>>>>>>>>>>>>>>>>>>加载机构语言配置开始<<<<<<<<<<<<<<<<<<<");
		loadGroupLanguageDate();
		log.info(">>>>>>>>>>>>>>>>>>>>>加载机构语言配置结束<<<<<<<<<<<<<<<<<<<");
	}

	/**
	 * 加载机构语言配置数据
	 */
	public void loadGroupLanguageDate() {

		List<UacGroupLanguage> uacGroupLanguageList = uacGroupLanguageService.selectAll();

		for (UacGroupLanguage ugl : uacGroupLanguageList) {
			redisTemplate.opsForValue().set(RedisKeyUtil.getUacGroupLanguageId(ugl.getGroupId()), ugl.getLanguage());
		}
	}
}